package com.kc.gb.device.events;

import com.kc.gb.device.JavaFxStarter;
import com.kc.gb.device.common.dto.RefreshUIEvent;
import com.kc.gb.device.service.HomeAdminService;
import com.kc.gb.device.tools.SSEStore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Resource;

@Slf4j
@Configuration
public class RefreshUIEventListener {

    @Resource
    HomeAdminService deviceAdminService;

    @Async
    @EventListener(value = RefreshUIEvent.class)
    public void onRefresh(RefreshUIEvent event) throws Exception {
        String deviceCode = deviceAdminService.getDeviceCode();
        String stationCode = deviceAdminService.getApplicationStationCode(deviceCode);
        //默认界面需要刷新数据
        SSEStore.sendRefreshEvent(event.getPublisher());
    }



}
